package com.ruoyi.hospital.controller.storeInfo;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hospital.domain.storeInfo.StoreSysUser;
import com.ruoyi.hospital.service.storeInfo.IStoreUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 药店用户Controller
 * 
 * @author wendao
 * @date 2024-09-18
 */
@RestController
@RequestMapping("/hospital/storeUser")
public class StoreUserController extends BaseController
{
    @Autowired
    private IStoreUserService storeSysUserService;

    /**
     * 查询药店用户列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:storeUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(StoreSysUser storeSysUser)
    {
        startPage();
        List<StoreSysUser> list = storeSysUserService.selectStoreSysUserList(storeSysUser);
        return getDataTable(list);
    }

    /**
     * 导出药店用户列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:storeUser:export')")
    @Log(title = "药店用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StoreSysUser storeSysUser)
    {
        List<StoreSysUser> list = storeSysUserService.selectStoreSysUserList(storeSysUser);
        ExcelUtil<StoreSysUser> util = new ExcelUtil<StoreSysUser>(StoreSysUser.class);
        util.exportExcel(response, list, "药店用户数据");
    }

    /**
     * 获取药店用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:storeUser:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Integer userId)
    {
        return success(storeSysUserService.selectStoreSysUserByUserId(userId));
    }

    /**
     * 新增药店用户
     */
    @PreAuthorize("@ss.hasPermi('hospital:storeUser:add')")
    @Log(title = "药店用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StoreSysUser storeSysUser)
    {
        return toAjax(storeSysUserService.insertStoreSysUser(storeSysUser));
    }

    /**
     * 修改药店用户
     */
    @PreAuthorize("@ss.hasPermi('hospital:storeUser:edit')")
    @Log(title = "药店用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StoreSysUser storeSysUser)
    {
        return toAjax(storeSysUserService.updateStoreSysUser(storeSysUser));
    }

    /**
     * 删除药店用户
     */
    @PreAuthorize("@ss.hasPermi('hospital:storeUser:remove')")
    @Log(title = "药店用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Integer[] userIds)
    {
        return toAjax(storeSysUserService.deleteStoreSysUserByUserIds(userIds));
    }
}
